home *** CD-ROM | disk | FTP | other *** search
/ ASP Advantage 1993 / The Association of Shareware Professionals Advantage CD-ROM 1993.iso / files / commions / ca29_1 / ca29_3.exe / DIALER.CMD < prev    next >
OS/2 REXX Batch file  |  1992-11-14  |  22KB  |  865 lines

  1. ; ----- COM-AND Multi-dialer script
  2. ;
  3. ;    This script opens a window and asks for up to 10 dialing directory
  4. ;    numbers (with or without long distance prefix).  As numbers are
  5. ;    selected, the dialing directory values are displayed (and the dialing
  6. ;    directory may be cycled through, searching).
  7. ;
  8. ;    When dialing is initiated, the current selections are saved to a file
  9. ;    on the current drive/subdirectory named DIALER.DAT.  If a connection
  10. ;    is made, the DIALER.DAT is updated to eliminate the connection just
  11. ;    made from the list.
  12. ;
  13. ;    If a script is associated with the dialing directory entry to which
  14. ;    connection is made, it is EXECUTED just as if from Alt-D.
  15. ;
  16. ;    R.McG, commenced 10/88
  17. ;           updated      3/89 (CLOG start and hit, and add alarm)
  18. ;           updated     10/92 (Fixes; changed for area code strip, dd changes)
  19. ; ----- Usages -----------------
  20. ;    S19 -----> Parameter string read/written to the .DAT file
  21. ;    N8 ------> Saved cursor row #
  22. ;    N9 ------> Saved cursor col #
  23. ;    N10-N19 -> Working storage for the screen display (LD# and DD#)
  24. ; ------------------------------
  25. ;    Initialization
  26. ;
  27. ;* TRACE ON
  28.    CLEAR
  29.    CURSOR N8,N9             ; Save cursor on entry
  30.    ON ESCAPE GOSUB Exit         ; SAVE is performed in Window
  31.    LEGEND " Multi-dialer pop-up"
  32.    SET TTHRU OFF            ; Disallow typeahead
  33.    CLOG "* Dialer multi-dialer invoked"
  34. ;
  35. ;    Paint an initial window, using saved values
  36. ;
  37.    GOSUB Window             ; Open the window
  38.    GOSUB Get_Last            ; Get last Parm string
  39.    GOSUB Parse_Parm            ; Parse_Parms
  40.    GOSUB All_Fields            ; Display all fields
  41.  
  42.    LOCATE 7,8                ; Set cursor to 1st entry
  43. ;
  44. ;    Main-loop - look for keyentry
  45. ;
  46. Main_Loop:
  47.    SET TTHRU OFF            ; Disallow typeahead
  48.    KEYGET S0                ; Get a keystroke
  49. ;
  50. ;    Act upon the keystroke
  51. ;
  52. Have_Key:
  53.    SWITCH S0
  54.       CASE "4900"                       ; Pgup
  55.      GOTO PgUp
  56.       ENDCASE
  57.       CASE "5100"                       ; PgDn
  58.      GOTO PgDn
  59.       ENDCASE
  60.       CASE "4700"                       ; Home
  61.      GOTO Home
  62.       ENDCASE
  63.       CASE "4F00"                       ; End
  64.      GOTO End
  65.       ENDCASE
  66.       CASE "0D"                         ; C/r
  67.      GOTO Perform
  68.       ENDCASE
  69.       CASE "4800"                       ; Cursor up
  70.      GOTO UpLine
  71.       ENDCASE
  72.       CASE "5000"                       ; Cursor down
  73.      GOTO DnLine
  74.       ENDCASE
  75.       CASE "4B00"                       ; Cursor Left
  76.      GOTO Left
  77.       ENDCASE
  78.       CASE "4D00"                       ; Cursor right
  79.      GOTO Right
  80.       ENDCASE
  81.       CASE "09"                         ; Tab
  82.      GOTO Right
  83.       ENDCASE
  84.       CASE "0F00"                       ; Shift-tab
  85.      GOTO Left
  86.       ENDCASE
  87.    ENDSWITCH
  88. ;
  89. ;     Any other keystrokes must be ASCII keys
  90. ;
  91.    IF NOT NULL S0(1:3)
  92.       SOUND 100,100
  93.       GOTO Main_Loop
  94.       ENDIF
  95. ;
  96. ;     Decide where we are by the current cursor, and begin field entry
  97. ;
  98.    CURSOR N0,N1
  99.    IF GE N1 11
  100.       GOSUB Enter_DD            ; Enter dialing directory #
  101.       GOTO Have_Key            ; Return with a new keystroke
  102.    ELSE
  103.       GOSUB Enter_LD            ; Enter Long distance #
  104.       GOTO Right            ; Move to next field
  105.       ENDIF
  106. ;
  107. ; ----- Page up (cycle backwards through possible values)
  108. ;
  109. PgUp:
  110.    CURSOR N1,N2
  111.    IF GE N2 11
  112.       N0 = N10[N1-7]
  113.       N3 = N0/1000            ; Cycle DD#
  114.       N0 = N0-(N0/1000)*1000
  115.       N0 = N0-1
  116.       IF LT N0 0 N0 = 100
  117.       N0 = N0+N3*1000
  118.    ELSE
  119.       N0 = N10[N1-7]
  120.       N3 = N0-(N0/1000)*1000        ; Cycle LD#
  121.       N0 = N0/1000
  122.       N0 = N0-1
  123.       IF LT N0 0 N0 = 4
  124.       N0 = N3+N0*1000
  125.       ENDIF
  126. ;
  127. ;    Restore the value (N0, index N1) and display
  128. ;
  129.    N10[N1-7] = N0
  130.    GOSUB One_Field
  131.    GOTO Main_Loop
  132. ;
  133. ; ----- Page down (cycle forwards through possible values)
  134. ;
  135. PgDn:
  136.    CURSOR N1,N2
  137.    IF GE N2 11
  138.       N0 = N10[N1-7]
  139.       N3 = N0/1000            ; Cycle DD#
  140.       N0 = N0-(N0/1000)*1000
  141.       N0 = N0+1
  142.       IF GT N0 100 N0 = 0
  143.       N0 = N0+N3*1000
  144.       N10[N1-7] = N0
  145.       GOSUB One_Field
  146.    ELSE
  147.       N0 = N10[N1-7]
  148.       N3 = N0-(N0/1000)*1000        ; Cycle LD#
  149.       N0 = N0/1000
  150.       N0 = N0+1
  151.       IF GT N0 4 N0 = 0
  152.       N0 = N3+N0*1000
  153.       ENDIF
  154. ;
  155. ;    Restore the value (N0, index N1) and display
  156. ;
  157.    N10[N1-7] = N0
  158.    GOSUB One_Field
  159.    GOTO Main_Loop
  160. ;
  161. ; ----- Up a line
  162. ;
  163. UpLine:
  164.    CURSOR N0,N1
  165.    N0 = N0-1
  166.    IF LT N0 7 N0 = 16
  167.    N1 = 8                ; Set new start-of-field
  168.    IF GE N1 11 N1 = 11            ; Set new start-of-field
  169.    LOCATE N0,N1
  170.    GOTO Main_Loop
  171. ;
  172. ; ----- Down a line
  173. ;
  174. DnLine:
  175.    CURSOR N0,N1
  176.    N0 = N0+1
  177.    IF GT N0 16 N0 = 7
  178.    N1 = 8                ; Set new start-of-field
  179.    IF GE N1 11 N1 = 11
  180.    LOCATE N0,N1
  181.    GOTO Main_Loop
  182. ;
  183. ; ----- Home (move to first line)
  184. ;
  185. Home:
  186.    LOCATE 7,8
  187.    GOTO Main_Loop
  188. ;
  189. ; ----- End (Move to last line)
  190. ;
  191. End:
  192.    LOCATE 11,8
  193.    GOTO Main_Loop
  194. ;
  195. ; ----- Left (Next field)
  196. ;
  197. Left:
  198.    CURSOR N0,N1
  199.    IF GE N1 11
  200.       N1 = 8                ; Move to previous field
  201.    ELSE
  202.       N0 = N0-1             ; Move to previous line
  203.       N1 = 11
  204.       ENDIF
  205.    IF LT N0 7 N0 = 16            ; Last field
  206.    LOCATE N0,N1             ; And reposition cursor
  207.    GOTO Main_Loop
  208. ;
  209. ; ----- Right (Previous field)
  210. ;
  211. Right:
  212.    CURSOR N0,N1
  213.    IF GE N1 11
  214.       N0 = N0+1             ; Move to next row
  215.       N1 = 8
  216.    ELSE
  217.       N1 = 11                ; Move to next field
  218.       ENDIF
  219.    IF GT N0 16 N0 = 7            ; Last field
  220.    LOCATE N0,N1             ; And reposition cursor
  221.    GOTO Main_Loop
  222. ;
  223. ; ----- Subroutine Exit - terminate the process
  224. ;
  225. Exit:
  226.    RESTORE                ; Saved screen
  227.    LOCATE N8,N9             ; Restore cursor
  228.    EXIT
  229. ;
  230. ; ----- Subroutine: Enter a dialing directory #
  231. ;    .. on entry S0 -> The first keystroke
  232. ;    .. N1 within this subroutine is always current row#
  233. ;    .. S9 within this subroutine the field being constructed
  234. ;    .. N6 within this subroutine is an index to field being constructed
  235. ;
  236. Enter_DD:
  237.    CURSOR N1,N2             ; Get current row
  238.    N0 = N10[N1-7]
  239.    N0 = (N0/1000)*1000            ; Fake a 0 DD# with old LD#
  240.    GOSUB One_Field            ; Clear previous values on screen
  241.    N6 = 0                ; Index to field being built
  242.    S9 = ""                              ; Clear field
  243. ;
  244. ;    Look for an initial space or backspace (this 'blank's the field)
  245. ;
  246.    IF STRCMP S0 " "                     ; If enter with space
  247.       N10[N1-7] = N0
  248.       GOTO DD_Keypress            ; Start w/new key
  249.       ENDIF
  250.    IF STRCMP S0 "08"                    ; If enter with backspace
  251.       N10[N1-7] = N0
  252.       GOTO DD_Keypress            ; Start w/new key
  253.       ENDIF
  254. ;
  255. ;    The space bar terminates data entry
  256. ;
  257. DD_Test:
  258.    IF STRCMP S0 " "                     ; If space key
  259.       S0 = "4D00"                       ; Fake a cursor right
  260.       GOTO DD_Store            ; End of routine
  261.       ENDIF
  262. ;
  263. ;    A "?" pops up the dialing directory
  264. ;
  265.    IF STRCMP S0 "?"                     ; If enter with backspace
  266.       GOSUB Ask_Dial            ; Display dialing directory
  267.       IF SUCCESS            ; If an entry selected..
  268.      S9 = S2            ; Move to accumulator string
  269.      LENGTH S9 N6            ; Length of entry
  270.      S0 = "4D00"                    ; Fake a cursor right
  271.      GOTO DD_Store            ; ANd use it
  272.      ENDIF
  273.       GOTO DD_Keypress            ; Else start over
  274.       ENDIF
  275. ;
  276. ;    Look for special chars (tab, and backspace, and non-ASCII)
  277. ;
  278.    SWITCH S0
  279.       CASE "09"                         ; Tab key
  280.      GOTO DD_Store
  281.       ENDCASE
  282.       CASE "0D"                         ; Carriage rtn end field here
  283.      S0 = "4D00"                    ; Fake a cursor right
  284.      GOTO DD_Store
  285.       ENDCASE
  286.       CASE "08"                         ; Backspace
  287.      IF GT N6 0            ; If anything entered
  288.         CURSOR N1,N2
  289.         N2 = N2-1
  290.         LOCATE N1,N2
  291.         ATSAY  N1,N2 (default) " "
  292.         S1(N6:N6) = " "
  293.         N6 = N6-1
  294.         ENDIF
  295.      GOTO DD_Keypress        ; And go for another key
  296.       ENDCASE
  297.    ENDSWITCH
  298.    IF NOT NULL S0(1:3) GOTO DD_Store    ; Not ascii key
  299. ;
  300. ;    Filter only numeric chars here
  301. ;
  302.    CTOI S0 N0                ; Easier comparison
  303.    IF LT N0 48 GOTO DD_Invalid        ; 48 = '0'
  304.    IF GT N0 57 GOTO DD_Invalid        ; 56 = '9'
  305. ;
  306. ;    Add the character to our field being constructed
  307. ;
  308.    S9(N6:N6) = S0            ; Add the char
  309.    N6 = N6+1
  310. ;
  311. ;    Display the keystroke in S0
  312. ;
  313.    CURSOR N1,N2
  314.    ATSAY N1,N2 (default) S0(0:0)
  315.    N2 = N2+1                ; Increment cursor
  316.    LOCATE N1,N2
  317. ;
  318. ;    Loop for more (unless field is full)
  319. ;
  320.    IF GE N6 3                ; 3 digits entered
  321.       S0 = "4D00"                       ; Fake a cursor right
  322.       GOTO DD_Store            ; Can't be more
  323.       ENDIF
  324.    GOTO DD_Keypress
  325. ;
  326. ;    Invalid keypress
  327. ;
  328. DD_Invalid:
  329.    SOUND 100,100
  330. ;
  331. ;    Request the next key
  332. ;
  333. DD_Keypress:
  334.    KEYGET S0
  335.    GOTO DD_Test
  336. ;
  337. ;    Update the remainder of the display too
  338. ;
  339. DD_Store:
  340.    IF EQ N6 0 GOTO DD_Exit        ; Nothing stored
  341.    N3 = S9                ; Save current value
  342.    IF GT N3 100 N3 = 100        ; Set upper bound
  343.    IF LT N3 1 N3 = 1            ; Set lower bound
  344.    N0 = N10[N1-7]
  345.    N0 = N3+(N0/1000)*1000        ; Add new DD# and old LD#
  346.    N10[N1-7] = N0
  347. ;
  348. ;    Update the display and we're done
  349. ;
  350. DD_Exit:
  351.    N0 = N10[N1-7]
  352.    GOSUB One_Field            ; Using N0,N1
  353.    RETURN
  354. ;
  355. ; ----- Subroutine: Enter a long distance #
  356. ;    .. on entry S0 -> The first keystroke
  357. ;
  358. Enter_LD:
  359.    SWITCH S0
  360.      CASE "+"
  361.     N0 = 1
  362.      ENDCASE
  363.      CASE "-"
  364.     N0 = 2
  365.      ENDCASE
  366.      CASE "#"
  367.     N0 = 3
  368.      ENDCASE
  369.      CASE "@"
  370.     N0 = 4
  371.      ENDCASE
  372.      CASE "1"
  373.     N0 = 1
  374.      ENDCASE
  375.      CASE "2"
  376.     N0 = 2
  377.      ENDCASE
  378.      CASE "3"
  379.     N0 = 3
  380.      ENDCASE
  381.      CASE "4"
  382.     N0 = 4
  383.      ENDCASE
  384.      DEFAULT
  385.     N0 = 0
  386.     S0 = " "
  387.      ENDCASE
  388.    ENDSWITCH
  389. ;
  390. ;    Clear the field, and redisplay
  391. ;
  392.    CURSOR N1,N2
  393.    ATSAY  N1,N2 (Default) S0(0:0)
  394. ;
  395. ;    Update the remainder of the display too
  396. ;
  397.    N3 = N0                ; Save current value
  398.    N0 = N10[N1-7]
  399.    N0 = N0-(N0/1000)*1000        ; Extract DD#
  400.    N0 = N0+N3*1000            ; Add new DD#
  401.    N10[N1-7] = N0
  402. ;
  403. ;    Flesh out the display and we're done
  404. ;
  405.    GOSUB One_Field            ; Using N0,N1
  406.    RETURN
  407. ;
  408. ; ----- Display a single field
  409. ;    .. N0 -> The LD code*1000 + the dialing directory #
  410. ;       N1 -> The display line #
  411. ;    .. N2,N3,S10,S11 are modified
  412. ;
  413. One_Field:
  414.    S10 = "                                                                      "
  415.    ATSAY N1,7  (Default) S10(0:67)
  416.    IF ZERO N0 RETURN            ; Return if no entry
  417. ;
  418. ;    Extract the LD code and dialing directory #
  419. ;
  420.    N2 = N0/1000             ; Set LD #
  421.    N3 = N0-(N0/1000)*1000        ; Set dialing directory #
  422. ;
  423. ;    Set-up the LD code for display
  424. ;
  425.    IF NOT ZERO N2
  426.       S10(0:2) = " "*N2
  427.       LD S11 N2
  428.       S10(8:30) = S11
  429.       ENDIF
  430. ;
  431. ;    Set-up the dialing directory # for display
  432. ;
  433.    IF NOT ZERO N3
  434.       S10(4:6) = N3
  435.       DNUM S11 N3
  436.       S10(32:45) = S11
  437.       DIRECTORY S11 N3
  438.       S10(47:79) = S11
  439.       ENDIF
  440. ;
  441. ;    And display the entry
  442. ;
  443.    ATSAY N1,7  (Default) S10(0:67)
  444.    RETURN
  445. ;
  446. ; ----- Subroutine: Display all fields
  447. ;    .. N0,N1,N2,N3,S10,S11 are destroyed
  448. ;
  449. All_Fields:
  450.    FOR N20 = 0,9
  451.        N0 = N10[N20]            ; Get directory number
  452.        N1 = N20+7            ; Set display line
  453.        IF NOT ZERO N0 GOSUB One_Field    ; Display a single field
  454.        ENDFOR
  455.    RETURN                ; And we're done
  456. ;
  457. ; ----- Subroutine: Parse a parameter string in S19 into numeric variables
  458. ;    .. N10-N19 are returned either set to 0, or a dialing directory #
  459. ;       S19 -> The saved dialing command
  460. ;    .. N0,N1 are modifed
  461. ;
  462. Parse_Parm:
  463.    FOR N0 = 0,45,5            ; 10x
  464.      N1 = N0+3
  465.      ATOI S19(N0:N1) N1
  466.      IF ERROR N1 = 0            ; Delimiter
  467.      N10 = N11
  468.      N11 = N12
  469.      N12 = N13
  470.      N13 = N14
  471.      N14 = N15
  472.      N15 = N16
  473.      N16 = N17
  474.      N17 = N18
  475.      N18 = N19
  476.      N19 = N1
  477.      ENDFOR
  478.    RETURN
  479. ;
  480. ; ----- Subroutine: Get the last dialing parameter used
  481. ;    .. S19 returns the parameter
  482. ;
  483. Get_Last:
  484.    S19 = "DIALER.DAT"
  485.    IF ISFILE S19
  486.       FOPENI "DIALER.Dat" TEXT           ; Name of data file
  487.       IF FAILURE GOTO No_Get
  488.    ELSE
  489.       GOTO No_Get
  490.       ENDIF
  491. ;
  492. ;    Read the firt record in the file
  493. ;
  494.    READ S19 80 N0
  495.    IF EOF GOTO No_Get
  496.    FCLOSEI                ; Done for now
  497.    RETURN
  498. ;
  499. ;    No file or record
  500. ;
  501. No_Get:
  502.    S19 = "   "
  503.    RETURN
  504. ;
  505. ; ----- Open a window with blank fields
  506. ;
  507. Window:
  508.    SAVE   1,5  23 75
  509.    BOX      1,5  23 75 (default)
  510.    ATSAY  1,7  (default)   " COM-AND Multi-dialer "
  511.  
  512.    ATSAY  2,7  (default)   "Select up to 10 dialing directory entries (using or not using a long"
  513.    ATSAY  3,7  (default)   "distance prefix).  Sequential redial begins when you hit return."
  514.    ATSAY  4,5  (default) "├─────────────────────────────────────────────────────────────────────┤"
  515.    ATSAY  5,7  (default)   "LD# DD#   (from LD directory)        (from dialing directory)"
  516.    ATSAY  6,7  (default)   "--- --- ----------------------- -------------- --------------------"
  517.  
  518.    ATSAY 17,5  (default) "├─────────────────────────────────────────────────────────────────────┤"
  519.    ATSAY 18,7  (default)   "Use cursor up/down to select a line in the display.  Use cursor left"
  520.    ATSAY 19,7  (default)   "and right to select a field.  ?/PgUp/PgDn cycle possible values.  LD"
  521.    ATSAY 20,7  (default)   "codes are 0,' ' = none, 1 or +, 2 or -, 3 or #, 4 or @.  DD codes"
  522.    ATSAY 21,7  (default)   "are 1-100.  Current values are always displayed.  Empty entries "
  523.    ATSAY 22,7  (default)   "are ignored.  A carriage return begins the dialing sequence."
  524.    ATSAY 23,30 (default)            " Press ESC to exit "
  525.    RETURN
  526. ;
  527. ;    This exit is taken after we begin to perform the dialing sequence
  528. ;
  529. Exit_Perform:
  530.    HANGUP                ; HANGUP - may be dialing
  531.    RESTORE                ; Clear 2nd window
  532.    GOTO Exit
  533. ;
  534. ; ----- We are to perform the redial - is there anything?
  535. ;
  536. Perform:
  537.    N6 = 0
  538.    FOR N1 = 7,16
  539.        N0 = N10[N1-7]
  540.        N2 =  N0-N0/1000*1000        ; DD#
  541.        IF NOT ZERO N2 GOTO Set_up    ; If there's an entry here
  542.        ENDFOR
  543. ;
  544. ;    Nothing to do
  545. ;
  546.    SOUND 100,100
  547.    GOTO Main_Loop            ; And continue
  548. ;
  549. ;    Set-up a new environment
  550. ;
  551. Set_Up:
  552. ;* TRACE ON
  553.    SET TTHRU ON             ; Allow typethrough
  554.    KFLUSH
  555.    SET RDISP OFF            ; Turn off display
  556.    ON ESCAPE GOSUB Exit_Perform     ; New exit
  557.    LEGEND " Cycling through selected #'s"
  558. ;
  559. ;    Save the current selection for the next invocation
  560. ;
  561.    GOSUB Set_Last            ; Save whole list in case of Escape
  562. ;
  563. ;    Open a window over the last one.
  564. ;
  565.    SAVE   17,5 23 75
  566.    BOX      17,5 23 75 (default)
  567.    ATSAY  17,7    (default) " COM-AND Dialing "
  568.    ATSAY  23,22 (default) " CR to move to next, ESC to terminate "
  569. ;
  570. ;    Set control values
  571. ;
  572.    N6 = 0                ; Display counter
  573.    N5 = 35                ; TImeout in seconds
  574. ;
  575. ;    Loop until escape or connect
  576. ;    .. Note: N1 and N2 must be preserved within the loop
  577. ;
  578. Loop:
  579.    FOR N1 = 7,16            ; Loop index (preserve this value!)
  580.        ;
  581.        ;  Get the current entry's value (0 = not used)
  582.        ;
  583.        N0 = N10[N1-7]
  584.        N2 =  N0-N0/1000*1000        ; DD# (preserve this value!)
  585.        N3 =  N0/1000*1000        ; LD#
  586.  
  587.        IF NOT ZERO N2
  588.       N6 = N6+1
  589.       ATSAY 18,7  (default) "Retry #: "*N6*";  Started: "*"_time"*";  Timeout = "*N5*" seconds"
  590.       ATSAY 19,7  (default) "                              " ; clear
  591.       ATSAY 20,7  (default) "                              " ; clear
  592.       ATSAY 21,7  (default) "                              " ; clear
  593.       ATSAY 22,7  (default) "                              " ; clear
  594.       ;
  595.       ;  Using values for this entry get name, number and LD prefix
  596.       ;
  597.       DIRECTORY S1 N2
  598.       DNUM S2 N2
  599.       LJ S2             ; Left justify
  600.       IF NOT NULL "_DDAC"           ; We're stripping area codes
  601.          S0 = "1-"*"_DDAC"          ; Make up the long distance form
  602.          LENGTH S0 N21        ; Find string len
  603.          IF STRCMP S0 S2(0:N21-1) S2 = S2(N21:79)
  604.          ENDIF
  605.       LD S3 N3
  606.       ATSAY 19,7  (default) S1
  607.       ATSAY 20,7  (default) S2&S3
  608.       ;
  609.       ;  Set parity, data and stop bits, echo, and speed
  610.       ;
  611.       GOSUB Set_Dialing
  612.       ;
  613.       ;  Hangup and send the dialing sequence
  614.       ;
  615.       RFLUSH
  616.       ATSAY 22,7  (default) "Hanging up  "
  617.       HANGUP
  618.       WAITFOR "OK" 10               ; Clear line of modem's "OK"
  619.       PAUSE 1
  620.       S0 = "_DPRE" & S3&"" & S2&"" & "_DSUF" & ""
  621.       TRANS S0
  622.       ATSAY 22,7  (default) "Dialing     "
  623.       ;
  624.       ;  Wait for a non-null response from the modem
  625.       ;
  626.       N0 = N5
  627.       SET TIMER
  628.       WHILE GT N0 0
  629.          RGET S0 80 N0        ; Wait up to a limit secs
  630.          IF NOT NULL S0
  631.         IF FIND S0 "_MCONNECT"&""  ; Trim trailing blanks
  632.            GOTO Got_It
  633.         ELSE
  634.            ATSAY 22,7  (default) "                             "
  635.            ATSAY 22,7  (default) S0
  636.            IF NOT FIND S0 S2&"" and NOT FIND S0 "RINGING"
  637.               ATSAY 22,7  (default) "Cycling                      "
  638.               PAUSE 5
  639.               N0 = -N5        ; Force end of loop
  640.               ENDIF
  641.            ENDIF
  642.         ENDIF
  643.          TSINCE N3,N3,N4        ; Throw away Hrs
  644.          IF N0 GT 0 N0 = N5-N4    ; Compute total time
  645.          ENDWHILE
  646.       ENDIF
  647.        ENDFOR
  648.    GOTO Loop                ; Loops forever - 'til ESC or connect
  649. ;
  650. ; ----- Subroutine: Set for dialing
  651. ;    .. N2 on entry is the directory #
  652. ;
  653. Set_Dialing:
  654.    DPARM S0 N2                ; Get dialing parms
  655.    ATSAY 21,7  (default) S0
  656.  
  657.    S1 = S0(5:5)
  658.    SWITCH S1                ; Parity
  659.       CASE "E"
  660.     SET PARITY EVEN
  661.       ENDCASE
  662.       CASE "O"
  663.     SET PARITY ODD
  664.       ENDCASE
  665.       CASE "N"
  666.     SET PARITY NONE
  667.       ENDCASE
  668.    ENDSWITCH
  669.  
  670.    S1 = S0(7:7)
  671.    SET DATA S1
  672.  
  673.    S1 = S0(9:9)
  674.    SET STOP S1
  675.  
  676.    IF NOT STRCMP "_DDOVER" "ON"         ; If dd not overridden
  677.       SET BAUD S0(0:3)
  678.       ENDIF
  679.  
  680.    SET DUPLEX FULL            ; Default...
  681.    IF STRCMP S0(11:11) "Y" SET DUPLEX HALF ; Echo Y/N
  682.    RETURN
  683. ;
  684. ; ----- We got a connection
  685. ;    .. N1 -> The selected entry
  686. ;
  687. Got_It:
  688.    RESTORE                ; Clear 2nd window
  689.    RESTORE                ; Clear 1st window
  690.    LOCATE N8,N9             ; Restore cursor
  691.    SET RDISP ON             ; Turn on display
  692. ;
  693. ;    Clear the entry selected here from the saved list
  694. ;
  695.    N0 = 0                ; Set cleared value
  696.    N10[N1-7] = N0
  697.    GOSUB Set_Last            ; Save updated list for next time
  698. ;
  699. ;    Log connection
  700. ;
  701.    DIREC S0 N2                ; Get the name
  702.    SET CLOCK NEW            ; Turn on screen clock
  703.    CLOG "CONNECT (dialer.cmd): "*S0
  704. ;
  705. ;    If this entry has a script, execute it
  706. ;
  707.    DSCRIPT S0,N2            ; Look for a script
  708.    IF NOT NULL S0
  709.       SET LINKED ON            ; Fake from Alt-D
  710.       EXECUTE S0            ; Chain to new script
  711.       ENDIF
  712.    ALARM                ; SOund an alarm (if enabled)
  713.    CONNECT                ; Go to terminal mode
  714. ;
  715. ; ----- Subroutine: Store current selections for next use
  716. ;    .. S19 is modified
  717. ;
  718. Set_Last:
  719.    S19 = "DIALER.DAT"
  720.    FOPENO "DIALER.Dat" TEXT           ; Name of data file
  721.    IF FAILURE RETURN
  722.    S19(0:4)   = N10
  723.    S19(5:9)   = N11
  724.    S19(10:14) = N12
  725.    S19(15:19) = N13
  726.    S19(20:24) = N14
  727.    S19(25:29) = N15
  728.    S19(30:34) = N16
  729.    S19(35:39) = N17
  730.    S19(40:44) = N18
  731.    S19(45:49) = N19
  732.    WRITE S19 50
  733.    FCLOSEO
  734.    RETURN
  735. ;
  736. ; ----- Subroutine: Ask for the number to dial
  737. ;    S2 returns the selected entry # or null
  738. ;
  739. Ask_Dial:
  740.    N20 = 0            ; Page #
  741.    WOPEN  2 20 15 60 (contrast) ASK_ESC
  742.    ATSAY  2 22 (contrast) " Learn Dial  "
  743.    ATSAY 13 20 (contrast)  "├───────────────────────────────────────┤"
  744.    ATSAY 14 22 (contrast) "Entry# (or m):"
  745.    ATSAY 15 30 (contrast) " Press ESC to cancel "
  746.    CURSOR N5 N6
  747.    SET FLAG(9) OFF        ; Escape pressed
  748.    ;
  749.    ;    Display the current page
  750.    ;
  751. Dial_Loop:
  752.    SCROLL 0,  3,22 12,58 (contrast) ; Clear display area
  753.    FOR N21 = 1,10
  754.        N24 = N20+N21
  755.        DIRECTORY S0 N24
  756.        ATSAY (2+N21) 22 (contrast) N24*")"
  757.        ATSAY (2+N21) 27 (contrast) S0
  758.        ENDFOR
  759.    LOCATE 14 37
  760.    N22 = 37            ; Currnt cursor
  761.    S2 = ""                      ; Clear save buffer
  762.    ;
  763.    ;    Wait for a keypress
  764.    ;
  765. Dial_Key:
  766.    IF NOT FLAG(9) KEYGET S0    ; Read keypress
  767.    IF FLAG(9)            ; Esc was pressedn
  768.       WCLOSE
  769.       SET SUCCESS OFF        ; Report to caller
  770.       RETURN
  771.       ENDIF
  772.    LENGTH S0 N21
  773.    SWITCH N21            ; Switch on length
  774.       CASE 1            ; Len = 1: ASCII char
  775.      IF FIND S0 "m"         ; Manual dialing
  776.         S2 = S0        ; Set string
  777.         SET SUCCESS ON    ; Report success
  778.         GOTO Dial_End    ; .. and get out
  779.         ENDIF
  780.      IF NOT FIND "+-@#0123456789" S0
  781.         SOUND 100,100
  782.         GOTO Dial_Key
  783.         ENDIF
  784.      S2 = S2*S0        ; Save the keypress
  785.      ATSAY 14 N22 (contrast) S0
  786.      INC N22        ; Increment cursor
  787.      LOCATE 14 N22
  788.      GOTO Dial_Key
  789.       ENDCASE
  790.       CASE 2            ; Len = 2: ctl char
  791.      SWITCH S0        ; Handle individual ctl chars
  792.         CASE "0D"           ; Carriage rtn
  793.            SET SUCCESS ON
  794.            GOTO DIAL_End
  795.         ENDCASE
  796.         CASE "08"           ; Carriage rtn
  797.            LENGTH S2 N20
  798.            IF GT N20 1
  799.           S2 = S2(0:N20-2)
  800.           DEC N22    ; Increment cursor
  801.           LOCATE 14 N22
  802.           ATSAY 14 N22 (contrast) " "
  803.            ELSE
  804.           S2 = ""       ; Clear field so far
  805.           N22 = 37
  806.           ATSAY 14 N22 (contrast) " "
  807.           ENDIF
  808.            GOTO Dial_Key
  809.         ENDCASE
  810.         DEFAULT        ; Any other ctl char
  811.            SOUND 100,100
  812.            GOTO Dial_Key
  813.         ENDCASE
  814.      ENDSWITCH
  815.       ENDCASE            ; End len = 2
  816.       CASE 4
  817.      SWITCH S0        ; Len = 4: Ftn key
  818.         CASE "4900"         ; PgUp
  819.           N20 = N20-10
  820.           IF LT N20 0
  821.          N20 = 90
  822.          ENDIF
  823.           GOTO Dial_Loop
  824.         ENDCASE
  825.         CASE "5100"         ; PgDn
  826.           N20 = N20+10
  827.           IF GE N20 100
  828.          N20 = 0
  829.          ENDIF
  830.           GOTO Dial_Loop
  831.         ENDCASE
  832.         CASE "4700"         ; Home
  833.           N20 = 0
  834.           GOTO Dial_Loop
  835.         ENDCASE
  836.         CASE "4F00"         ; End
  837.           N20 = 90
  838.           GOTO Dial_Loop
  839.         ENDCASE
  840.         DEFAULT        ; Any other ftn keyr
  841.            SOUND 100,100
  842.            GOTO Dial_Key
  843.         ENDCASE
  844.      ENDSWITCH
  845.       ENDCASE
  846.       DEFAULT            ; Len <> 1,2,4... e.g. esc
  847.      SET SUCCESS OFF
  848.       ENDCASE
  849.    ENDSWITCH
  850. ;
  851. ;    End of dial select
  852. ;
  853. Dial_End:
  854.    SET SUCCESS ON        ; Return success
  855.    LOCATE N5 N6         ; Return cursor...
  856.    WCLOSE
  857.    RETURN            ; And done
  858. ;
  859. ; ----- Escape during a subwindow
  860. ;    .. S0 is returned null
  861. ;
  862. Ask_Esc:
  863.    SET FLAG(9) ON        ; Make a null return
  864.    RETURN
  865.